from model.Hero import Hero
from model.events.Event import Event
from view.blockImgs.EventImg import EventImg

monster_data = [{
    "id": 0,
    "name": "骷髏",
    "img": "0",
    "hp": 80,
    "atk": 45,
    "dfs": 0,
    "agility": 5,
    "dex": 5,
    "money": 4,
    "info": "死去的⼈們怨氣遲遲不肯散去，附身在屍⻣上，便形成了骷髏。"
}, {
    "id": 1,
    "name": "骷髏戰⼠",
    "img": "1",
    "hp": 120,
    "atk": 85,
    "dfs": 50,
    "money": 8,
    "info": "死去的⼈們怨氣遲遲不肯散去，附身在屍⻣上，便形成了骷髏。"
}, {
    "id": 2,
    "name": "綠⾊史萊姆",
    "img": "8",
    "hp": 15,
    "atk": 18,
    "dfs": 0,
    "money": 1,
    "info": "黏糊糊的綠⾊史萊姆，有點膽⼩、害羞。"
}, {
    "id": 3,
    "name": "紅⾊史萊姆",
    "img": "9",
    "hp": 25,
    "atk": 28,
    "dfs": 2,
    "money": 2,
    "info": "黏糊糊的紅⾊史萊姆，膽⼦很⼤，平時最愛去冒險。"
}, {
    "id": 4,
    "name": "⿊⾊史萊姆",
    "img": "10",
    "hp": 40,
    "atk": 35,
    "dfs": 5,
    "money": 5,
    "info": "黏糊糊的⿊⾊史萊姆，是史萊姆三兄弟的⼤哥，最有義氣的他總是保護懦弱的綠⾊史萊姆。"
}, {
    "id": 5,
    "name": "⼩蝙蝠",
    "img": "4",
    "hp": 36,
    "atk": 38,
    "dfs": 8,
    "money": 3,
    "info": "蝙蝠，翼⼿⽬是哺乳動物中僅次於齧⿒⽬動物的第⼆⼤類群，也是唯⼀可以⾶⾏的哺乳類動物。"
}, {
    "id": 6,
    "name": "⼤蝙蝠",
    "img": "5",
    "hp": 72,
    "atk": 55,
    "dfs": 28,
    "money": 10,
    "info": "⼤蝙蝠有著較⼩蝙蝠更加敏捷的速度，可以在⼀回合內攻擊兩次。"
}, {
    "id": 7,
    "name": "殭屍",
    "img": "16",
    "hp": 80,
    "atk": 45,
    "dfs": 32,
    "money": 13,
    "info": "已經沒有思考能⼒的殭屍全憑本能來戰⾾，⼩⼼別被他的⽖⼦抓傷！"
}, {
    "id": 8,
    "name": "初階武⼠",
    "img": "20",
    "hp": 220,
    "atk": 60,
    "dfs": 32,
    "agility": 0,
    "money": 20,
    "info": "⼀群有夢想的年輕⼈，剛剛通過了武⼠檢定，崇尚所謂「武⼠精神」最看重⾃⼰的榮譽。"
}, {
    "id": 9,
    "name": "中階武⼠",
    "img": "21",
    "hp": 450,
    "atk": 120,
    "dfs": 140,
    "money": 30,
    "info": "曾在沙場上拋頭顱灑熱⾎的武⼠，無懼⼀切的他們，⾯對敵⼈他們絕對不會⼼軟。"
}, {
    "id": 10,
    "name": "亡靈護衛",
    "img": "40",
    "hp": 250,
    "atk": 160,
    "dfs": 250,
    "money": 45,
    "info": "靈魂不肯離開早已死亡的軀體，厚重的盔甲下，是戰⾾的本能。"
}, {
    "id": 11,
    "name": "騎⼠",
    "img": "41",
    "hp": 200,
    "atk": 145,
    "dfs": 75,
    "money": 20,
    "info": "騎⼠和武⼠⾮常的相似，武⼠有武⼠精神，⽽騎⼠遵循騎⼠精神。紳⼠的他們，舞起劍來可是精準⼜有⼒。"
}, {
    "id": 12,
    "name": "重甲騎⼠",
    "img": "42",
    "hp": 250,
    "atk": 250,
    "dfs": 160,
    "money": 50,
    "info": "穿上重甲的騎⼠防禦⼒⼤幅提⾼，雖然重甲讓他們移動變的更加吃⼒，但是攻擊起來可是⼀點也不含糊的。"
},
    {
        "id": 13,
        "name": "亡靈騎⼠",
        "img": "43",
        "hp": 400,
        "atk": 250,
        "dfs": 125,
        "money": 60,
        "info": "已經化為亡靈的他們得到了更強⼤的能⼒，和無視重⼒的輕盈，擁有將⼀切⼊侵者斬殺的實⼒。"
    },
    {
        "id": 14,
        "name": "初階法師",
        "img": "12",
        "hp": 60,
        "atk": 10,
        "dfs": 10,
        "money": 6,
        "info": "法師的攻擊無視⼀切防禦。"
    },
    {
        "id": 15,
        "name": "⽯怪",
        "img": "18",
        "hp": 30,
        "atk": 20,
        "dfs": 85,
        "money": 5,
        "info": "具有超⾼防禦⼒的⽯頭⼈，攻擊和敏捷度都不怎麼樣，平時最喜歡把⾃⼰偽裝成⽯頭。"
    },
    {
        "id": 16,
        "name": "⼤史萊姆",
        "img": "11",
        "hp": 80,
        "atk": 55,
        "dfs": 24,
        "money": 11,
        "info": "⼤型的史萊姆。"
    },
    {
        "id": 17,
        "name": "幻影史萊姆",
        "img": "24",
        "hp": 160,
        "atk": 60,
        "dfs": 80,
        "money": 0,
        "info": "史萊姆的幻影，似乎在阻⽌你接近什麼。"
    }]


class Monster(Event):
    def __init__(self, x_position, y_position, monster_attribute):
        Event.__init__(self, x_position, y_position)
        self.step = 0
        self.monster_attribute = monster_attribute
        self.hp = monster_attribute["hp"]
        self.img_path = "resources/怪物/" + monster_attribute['img'] + ",%s.png" % self.step
        EventImg(self, x_position, y_position)
        self.isWork = True

    def trigger(self):
        Hero.direction = [0, 0, Hero.direction[2]]
        Hero.step = Hero.step % 4
        if self.isWork:
            self.isWork = False
            self.img_path = "resources/素材/magic_attack0 3.png"
            getDamage = Hero.attack - self.monster_attribute['dfs']
            if getDamage <= 0:
                getDamage = 1
            outDamage = self.monster_attribute['atk'] - Hero.defense
            if outDamage <= 0:
                outDamage = 1
            while self.hp > 0:
                self.hp -= getDamage
                Hero.hp -= outDamage
            Hero.money += self.monster_attribute['money']

    def update(self):
        if self.isWork:
            self.step += 1
            self.step = self.step % 16
            self.img_path = "resources/怪物/" + self.monster_attribute['img'] + ",%s.png" % (self.step // 4)
